package reit.ass3;


/**
 * The Class Pair.
 *
 * @param <A> the generic type
 * @param <B> the generic type
 */
class Pair<A, B> {

	/** The first. */
	private A first;

	/** The second. */
	private B second;

	/**
	 * Instantiates a new pair.
	 *
	 * @param first the first
	 * @param second the second
	 */
	public Pair(final A first, final B second) {
		super();
		this.first = first;
		this.second = second;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		int hashFirst = first != null ? first.hashCode() : 0;
		int hashSecond = second != null ? second.hashCode() : 0;

		return (hashFirst + hashSecond) * hashSecond + hashFirst;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(@SuppressWarnings("rawtypes") final Pair other) {
		if (other instanceof Pair) {
			//Pair otherPair = (Pair) other;
			return ((this.first == other.first || (this.first != null
					&& other.first != null && this.first
					.equals(other.first))) && (this.second == other.second || (this.second != null
					&& other.second != null && this.second
					.equals(other.second))));
		}

		return false;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return MyStringBuilder.buildString("(", first.toString() + ", ",
				second.toString(), ")");
	}

	/**
	 * Gets the first.
	 *
	 * @return the first
	 */
	public A getFirst() {
		return first;
	}

	/**
	 * Sets the first.
	 *
	 * @param first the new first
	 */
	public void setFirst(final A first) {
		this.first = first;
	}

	/**
	 * Gets the second.
	 *
	 * @return the second
	 */
	public B getSecond() {
		return second;
	}

	/**
	 * Sets the second.
	 *
	 * @param second the new second
	 */
	public void setSecond(final B second) {
		this.second = second;
	}

}
